package dyy.zc.sportruler.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import dyy.zc.sportruler.R;
import dyy.zc.sportruler.base.BaseActivity;
import dyy.zc.sportruler.bean.StudentInfo;
import dyy.zc.sportruler.bean.UserInfo;
import dyy.zc.sportruler.utils.ImageLoaderUtils;
import dyy.zc.sportruler.views.DragScaleImageView;

public class StudentDetailActivity extends BaseActivity {
    public int preHeight;//拉伸之前的高度
    public int width;//设置旋转图片的宽度
    private DragScaleImageView mDragScaleImageView;//可拉伸放大的背景图片
    private ImageView head, sex;//头像 性别
    private TextView name, phone, age, height, weight, jiaoling;//昵称 电话 年龄 身高 体重 教龄
    private TextView label,part,bmi,jiloulv,daixie;
    private RelativeLayout rl_check;
    public int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
    @Override
    protected void findViewByIDS() {
        head = findViewsById(R.id.activity_mylhome_iv_touxiang);
        name = findViewsById(R.id.activity_personalhome_tv_name);
        sex = findViewsById(R.id.activity_personalhome_iv_man);
        phone = findViewsById(R.id.textView2);
        age = findViewsById(R.id.activity_personalhome_tv_age);
        height = findViewsById(R.id.activity_personalhome_tv_tall);
        weight = findViewsById(R.id.activity_personalhome_tv_weight);
        jiaoling = findViewsById(R.id.activity_personalhome_tv_teachyear);
        mDragScaleImageView = (DragScaleImageView) findViewById(R.id.rl_head);
        rl_check = findViewsById(R.id.rl_check);
        label = findViewsById(R.id.label);
        part = findViewsById(R.id.part);
        bmi = findViewsById(R.id.bmi);
        jiloulv = findViewsById(R.id.jiroulv);
        daixie = findViewsById(R.id.daixie);
        initDragScaleImageView();
    }

    /**
     * 初始化拉伸图片
     */
    public void initDragScaleImageView() {
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        int width = metric.widthPixels;     // 屏幕宽度（像素）
        int height = metric.heightPixels;   // 屏幕高度（像素）
        preHeight = dip2px(this, 223);
        mDragScaleImageView.setImageWidthAndHeight(width, preHeight);
    }

    /**
     * 初始化个人信息
     */
    private void initData(StudentInfo studentInfo) {
        ImageLoaderUtils.initImage(this, studentInfo.getHead().getFileUrl(), head, R.mipmap.logo);
        name.setText(studentInfo.getName());
        if (studentInfo.isSex()) {
            sex.setImageResource(R.mipmap.man);
        } else {
            sex.setImageResource(R.mipmap.girl);
        }
        phone.setText(studentInfo.getPhone());
        age.setText(studentInfo.getAge());
        height.setText(studentInfo.getHeight());
        weight.setText(studentInfo.getWeight());
        jiaoling.setText(studentInfo.getTizhi());
        label.setText(studentInfo.getWanted());
        part.setText(studentInfo.getPart());
        bmi.setText("BMI:"+studentInfo.getBmi()+"");
        jiloulv.setText("肌肉率:"+studentInfo.getJiroulv()+"%");
        daixie.setText("基础代谢:"+studentInfo.getDaixie()+"(kcal/day)");
    }
    private void setTransparentBar() {
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            // Translucent status bar
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTransparentBar();
        setContentView(R.layout.activity_student_detail);
        bind();

    }
private StudentInfo studentInfo;
    private void bind() {
        studentInfo = (StudentInfo) getIntent().getSerializableExtra("student");
        initData(studentInfo);
        rl_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(StudentDetailActivity.this,MyPlanActivity.class);
                intent.putExtra("type",1);
                intent.putExtra("student",studentInfo.getName());
                startActivity(intent);
            }
        });
    }
}
